function [data] = load_panel_data_for_VAR_FE_intra_euro_FX(lag_number,euro_split)
% function [data] = load_panel_data_for_VAR_FE_intra_euro_FX(lag_number,splits)
% Inputs:
%   - lag_number        [integer]       number of lags
%   - euro_split        [boolean]       indicator for euro area split
%
% Outputs:
%   - data  	        [structur]      data for VAR

% Copyright (C) 2021-2023 Benjamin Born, Francesco D'Ascanio, Gernot J. Mueller, Johannes Pfeifer
%
% This is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% It is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
% 
% For a copy of the GNU General Public License,
% see <http://www.gnu.org/licenses/>.

if nargin==0
    lag_number=4;
end
load('../Figure 3+6 + Appendix C Descriptives/dataset_BDMP.mat');

if euro_split~=0
    [row,col] = find(data_array_for_regression_stacked_by_variable(:,:,pos.euro_country)==0);
    for ii=1:length(row)
        data_array_for_regression_stacked_by_variable(row(ii),col(ii),3:end)=NaN;
    end
end
time_fixed_effects_dummy=1;
country_fixed_effects_dummy=1;

regressor_var_names={'tax_revenue_real','g_real', 'y_real', 'Effective_FX_Real_Intra_Euro_CPI_log', 'spread_end_quarter','g_growth_fc_h1'};
dependent_var_names={'tax_revenue_real','g_real', 'y_real', 'Effective_FX_Real_Intra_Euro_CPI_log', 'spread_end_quarter','g_growth_fc_h1'};
data.var_names ={'T','G','Y','Intra-euro FX (up is apprecation)','Spread','Forecast'};

data_array_for_regression=[];
for lag_iter=1:lag_number
    for var_iter=1:length(regressor_var_names)
        data_array_control=data_array_for_regression_stacked_by_variable(:,:,pos.([regressor_var_names{var_iter},'_lag_',num2str(lag_iter)]));
        data_array_for_regression=cat(3,data_array_for_regression,data_array_control);
    end
end

dependent_variable=[];
for var_iter=1:length(dependent_var_names)
    dependent_variable_temp=squeeze(data_array_for_regression_stacked_by_variable(:,:,pos.(dependent_var_names{var_iter})));
    dependent_variable=cat(3,dependent_variable,dependent_variable_temp);
end

[data.VAR.Y,data.VAR.X,data.VAR.country_Fixed_Effects,data.VAR.time_Fixed_Effects,data.linear_indices]...
    =create_VAR_matrices_FE_removed(dependent_variable,data_array_for_regression,data_array_for_regression_stacked_by_variable,pos,country_indicator_names_mapping,time_fixed_effects_dummy,country_fixed_effects_dummy);